home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Lists / Link.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  699 b   |  35 lines  |  [TEXT/CWIE]

  1. // Link.h
  2.  
  3. #ifndef Link_h
  4. #define Link_h
  5.  
  6. #ifndef Assert_h
  7. #include "Assert.h"
  8. #endif
  9.  
  10. template < class TargetType >
  11. class Link
  12.   {
  13.     private:
  14.         TargetType *target;
  15.     
  16.     public:
  17.         Link( TargetType *t = 0 )
  18.           : target( t )
  19.           {}
  20.         
  21.         bool Null() const                            { return target == 0; }
  22.         void BeNull()                                { target = 0; }
  23.         
  24.         TargetType *Target() const                { return target; }
  25.         void PointTo( TargetType &t )            { target = &t; }
  26.  
  27.         void operator=( TargetType *t )        { target = t; }
  28.         operator TargetType *() const            { return target; }
  29.         
  30.         TargetType& operator*() const            { Assert( target != 0 ); return *target; }
  31.         TargetType *operator->() const        { Assert( target != 0 ); return target; }
  32.   };
  33.  
  34. #endif
  35.